package pub.developers.forum.portal.controller.admin;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pub.developers.forum.api.model.ResultModel;
import pub.developers.forum.api.request.comment.CommentCreateRequest;
import pub.developers.forum.api.response.article.ArticleQueryTypesResponse;
import pub.developers.forum.api.response.comment.CommentPageResponse;
import pub.developers.forum.api.service.CommentApiService;
import pub.developers.forum.common.constant.Constant;
import pub.developers.forum.common.enums.ErrorCodeEn;
import pub.developers.forum.facade.support.ResultModelUtil;
import pub.developers.forum.portal.support.WebUtil;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/admin-rest/comment") // 评论管理
public class AdminRestCommentController {
    @Resource
    private CommentApiService commentApiService;
    @PostMapping("/getList") //获取帖子全部的评论
    public ResultModel<List<CommentPageResponse>> getList(@RequestBody CommentCreateRequest createRequest, HttpServletRequest request) {
        request.setAttribute(Constant.REQUEST_HEADER_TOKEN_KEY, WebUtil.cookieGetSid(request)); //将token存储在请求对象中,判断用户是否登录
        try {
            ResultModel<List<CommentPageResponse>> resultModel = commentApiService.getListByPostId(createRequest.getPostsId());
            return resultModel;
        }catch (Exception e){
            return ResultModelUtil.fail(ErrorCodeEn.SYSTEM_ERROR);
        }
    }
}
